import _ from 'lodash';
let initState: any = [];

export const changeHistoryReducer = (state = initState, action: { type: string, data: Object }) => {
    let returnState = _.cloneDeep(state);
    switch (action.type) {
        case 'push':
            {
                returnState = [...returnState, action.data];
                return returnState;
            }
        case 'delete':
            {
                return returnState.reduce((pre: any, item: any, idx: number) => {
                    if (idx !== action.data) {
                        pre.push(item);
                    }
                    return pre;
                }, []);
            }
        default:
            return returnState;
    }
    //   reducer要return一个新的state去改写原本的state数据,
}